#!/bin/sh /etc/rc.common

SLAVES=/etc/dig1wire/slaves
MOUNT=/tmp/1wire

start()
{
   # Check if mount dir exists
   if [ ! -d $MOUNT ];
   then
      mkdir $MOUNT
   fi

   # Check if slaves file exists
   if [ ! -f $SLAVES ];
   then
      echo "Hardware type: SLAVE"
      mount_local_devices
   else
      echo "Hardware type: MASTER"

      # Mount slaves
      while read host
      do
         owfs -s $host -m $MOUNT
         echo $host "mounted."
      done < $SLAVES

      mount_local_devices
   fi

   echo "Mounting done."
}

# Try to mount device via USB
mount_local_devices()
{
   if [ -f /dev/ttyUSB0 ];
   then
      owfs -d /dev/ttyUSB0 $MOUNT
      echo "Mounting /dev/ttyUSB0"
   fi
}